package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.FeedbackBe;
import com.huilai.platform.country_platform.model.VillageFeedback;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.Date;

/**
 * 作者：洪霓
 * 日期：2023/3/3
 * 注释：
 */
public interface VillageFeedbackReposity extends JpaRepository<VillageFeedback, Integer>, JpaSpecificationExecutor<VillageFeedback> {
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into village_feedback(feedback_id, be_id, content_title, content_category, content_main, audit_status, type) " +
            "values(:#{#villageFeedback.feedbackId}, :#{#villageFeedback.beId}, :#{#villageFeedback.contentTitle}, :#{#villageFeedback.contentCategory}, :#{#villageFeedback.contentMain}, :#{#villageFeedback.auditStatus}, :#{#villageFeedback.type})", nativeQuery = true)
    Integer addFeedback(VillageFeedback villageFeedback);

    VillageFeedback findVillageFeedbackByContentTitle(String contentTitle);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update village_feedback vf set vf.audit_status = :auditStatus where vf.id = :id",nativeQuery = true)
    Integer updateAuditStatus(Integer id, Integer auditStatus);
}
